package com.ruoyi.common.enums.wecom;


import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum WecomMsgCallBackGroupChangeTypeEnum {
    GROUP_CREATE("create", "客户群创建事件"),
    GROUP_UPDATE("update", "客户群变更事件"),
    GROUP_DISMISS("dismiss", "客户群解散事件"),

    ;

    private final String code;
    private final String desc;


    private static final Map<String, WecomMsgCallBackGroupChangeTypeEnum> ENUM_MAP;

    static {
        WecomMsgCallBackGroupChangeTypeEnum[] values = values();
        Map<String, WecomMsgCallBackGroupChangeTypeEnum> enToCn = new HashMap<>(values.length);
        for (WecomMsgCallBackGroupChangeTypeEnum value : values) {
            enToCn.put(value.getCode(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static WecomMsgCallBackGroupChangeTypeEnum getEnumByType(String type) {
        WecomMsgCallBackGroupChangeTypeEnum wecomMsgCallBackGroupChangeTypeEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(wecomMsgCallBackGroupChangeTypeEnum)) {
            throw new RuntimeException("类型有误");
        }
        return wecomMsgCallBackGroupChangeTypeEnum;
    }


}
